from django.http import HttpResponse
from django.shortcuts import redirect, reverse


def index(request):
    username = request.GET.get('username')
    if username:
        return HttpResponse('首页')
    else:
        # TODO: 重定向到图书详情
        # book_detail_url = reverse('front:detail', kwargs={'book_id': 1})
        # print(book_detail_url)
        # return redirect(book_detail_url)
        login_url = reverse('front:login') + '?next=/'
        print(login_url)
        return redirect(login_url)


def book_detail(request, book_id):
    text = '图书ID：%s' % (book_id,)
    return HttpResponse(text)


def login(request):
    return HttpResponse('登录')
